package vote.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.view.RedirectView;
import vote.service.UserService;
import vote.service.WxService;

/**
 * Description:微信登录
 * Author:han
 * Date: 2024-05-21
 */
@Tag(name = "微信登录")
@RestController
@RequestMapping("/wx")
public class WxLoginController {
    @Resource
    private UserService userService;
    @Resource
    private WxService wxService;

    @GetMapping("/login")
    public RedirectView login(@RequestParam("callback") String callback, HttpServletResponse response) {
        RedirectView redirectView = new RedirectView();
        redirectView.setUrl(wxService.login(callback, response));
        return redirectView;
    }

    @GetMapping("/callback")
    public RedirectView callback(@RequestParam String code) {
        return wxService.solveCallback(code);
    }
}
